package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZsyyCommunityUserVo;
import com.ruoyi.system.bo.ZsyyCommunityUserQueryBo;
import com.ruoyi.system.bo.ZsyyCommunityUserAddBo;
import com.ruoyi.system.bo.ZsyyCommunityUserEditBo;
import com.ruoyi.system.service.IZsyyCommunityUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 业主信息管理Controller
 *
 * @author wangghua
 * @date 2021-07-14
 */
@ApiIgnore
@Api(value = "业主信息管理控制器", tags = {"业主信息管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/communityUser")
public class ZsyyCommunityUserController extends BaseController {

    private final IZsyyCommunityUserService iZsyyCommunityUserService;

    /**
     * 查询业主信息管理列表
     */
    @ApiOperation("查询业主信息管理列表")
    @PreAuthorize("@ss.hasPermi('system:communityUser:list')")
    @GetMapping("/list")
    public TableDataInfo<ZsyyCommunityUserVo> list(@Validated ZsyyCommunityUserQueryBo bo) {
        return iZsyyCommunityUserService.queryPageList(bo);
    }

    /**
     * 导出业主信息管理列表
     */
    @ApiOperation("导出业主信息管理列表")
    @PreAuthorize("@ss.hasPermi('system:communityUser:export')")
    @Log(title = "业主信息管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZsyyCommunityUserVo> export(@Validated ZsyyCommunityUserQueryBo bo) {
        List<ZsyyCommunityUserVo> list = iZsyyCommunityUserService.queryList(bo);
        ExcelUtil<ZsyyCommunityUserVo> util = new ExcelUtil<ZsyyCommunityUserVo>(ZsyyCommunityUserVo.class);
        return util.exportExcel(list, "业主信息管理");
    }

    /**
     * 获取业主信息管理详细信息
     */
    @ApiOperation("获取业主信息管理详细信息")
    @PreAuthorize("@ss.hasPermi('system:communityUser:query')")
    @GetMapping("/{id}")
    public AjaxResult<ZsyyCommunityUserVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iZsyyCommunityUserService.queryById(id));
    }

    /**
     * 新增业主信息管理
     */
    @ApiOperation("新增业主信息管理")
    @PreAuthorize("@ss.hasPermi('system:communityUser:add')")
    @Log(title = "业主信息管理", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZsyyCommunityUserAddBo bo) {
        return toAjax(iZsyyCommunityUserService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改业主信息管理
     */
    @ApiOperation("修改业主信息管理")
    @PreAuthorize("@ss.hasPermi('system:communityUser:edit')")
    @Log(title = "业主信息管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZsyyCommunityUserEditBo bo) {
        return toAjax(iZsyyCommunityUserService.updateByEditBo(bo) ? 1 : 0);
    }
    /**
     * 审核业主信息管理
     */
    @ApiOperation("审核业主信息管理")
    @PreAuthorize("@ss.hasPermi('system:communityUser:review')")
    @Log(title = "业主信息管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PostMapping("/review")
    public AjaxResult<Void> review(@Validated @RequestBody ZsyyCommunityUserEditBo bo) {
        return toAjax(iZsyyCommunityUserService.updateByEditBo(bo) ? 1 : 0);
    }
    /**
     * 添加卡
     */
    @ApiOperation("添加卡")
    @PreAuthorize("@ss.hasPermi('system:communityUser:addCardNum')")
    @Log(title = "业主信息管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping("/addCardNum")
    public AjaxResult<Void> addCardNum(@Validated @RequestBody ZsyyCommunityUserEditBo bo) {
        return toAjax(iZsyyCommunityUserService.addCardNum(bo) ? 1 : 0);
    }

    /**
     * 删除业主信息管理
     */
    @ApiOperation("删除业主信息管理")
    @PreAuthorize("@ss.hasPermi('system:communityUser:remove')")
    @Log(title = "业主信息管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iZsyyCommunityUserService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
    /**
     * 更新业主人脸
     */
    @ApiOperation("更新业主人脸")
    @PreAuthorize("@ss.hasPermi('system:communityUser:updateFace')")
    @Log(title = "业主信息管理" , businessType = BusinessType.UPDATE)
    @GetMapping("/updateFace/{id}")
    public AjaxResult<Void> updateFace(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long id) {
        return toAjax(iZsyyCommunityUserService.updateFace(id, true) ? 1 : 0);
    }
}
